package com.fotoloka.util;

import java.text.DecimalFormat;

public class NumberUtil {

	private static DecimalFormat df = new DecimalFormat();
	
	static {
		df.setDecimalSeparatorAlwaysShown(true);
	}
	
	public static double round(double valueToRound, int numberOfDecimalPlaces) {
		double multipicationFactor = Math.pow(10, numberOfDecimalPlaces);
		double interestedInZeroDPs = valueToRound * multipicationFactor;
		return Math.round(interestedInZeroDPs) / multipicationFactor;
	}
	
	public static String formatDecimal(Double decimal, int decimais) {
		if (decimal == null) {
			return "";
		}
		df.setMinimumFractionDigits(decimais);
		df.setMaximumFractionDigits(decimais);
		return df.format(decimal);
	}
	
	public static boolean isInteiro(String valor) {
		try {
			Integer.parseInt(valor);
			return true;
		} catch (Exception e) {
			//faz nada
		}
		return false;
	}

}
